<textarea name="${fieldname}" id="relatedArea_${fieldname}" style="width:250px;height:80px">${value!''}</textarea> <a href="javascript:;" id="selBtn_${fieldname}">从已有文章中选择</a>
<div id="articleDlg_${fieldname}"></div>
<script type="text/javascript">
var Related_${fieldname}={
	init:function(){
		var self = this;
		Eop.Dialog.init({id:'articleDlg_${fieldname}', width:600,height:300,title:'选择文章'});
		$("#selBtn_${fieldname}").click(function(){
			$("#articleDlg_${fieldname}").load("data!dlgList.do?ajax=yes&catid=1",function(){
				self.bindDlgEvent();
			});
			Eop.Dialog.open('articleDlg_${fieldname}');
		});
	},
	bindDlgEvent:function(){
		var self = this;
		self.createCatSelect();
		$("#articleDlg_${fieldname} .submitBtn").click(function(){
			self.selid();
		});
		$("#articleDlg_${fieldname} .filterBtn").click(function(){
			$.ajax({
				url:"data!dlgList.do?ajax=yes&catid="+$("#articleDlg_${fieldname} .catid").val(),
				type:'get',
				dataType:'html',
				success:function(html){
					$("#articleDlg_${fieldname} .gridbox").empty().append($(html).find(".gridbox").html());
					self.bindGridEvent();
				},
				error:function(){
					alert("加载列表失败");
				}
			}); 			
			
		});
		this.bindGridEvent();
	},
	createCatSelect:function(){
		$.ajax({
			url:'cat!showCatTree.do?cat_id=0&ajax=yes',
			type:'post',
			dataType:'html',
			success:function(selHtml){
				$("#articleDlg_${fieldname} .catbox").empty().append(selHtml);
			},
			error:function(){
				alert("加载类别树失败");
			}
		}); 
	},
	bindGridEvent:function(){
		var self  = this;
		function loadUrl(url){
			$.ajax({
				url:url,
				type:'get',
				dataType:'html',
				success:function(html){
					$("#gridbox").empty().append($(html).find("#gridbox").html());
					self.bindGridEvent();
				},
				error:function(){
					alert("加载列表失败");
				}
			}); 
	 
		}
		//EopPager.setLoadUrlFun(loadUrl);
	},
	selid:function(){
		var value =$("#relatedArea_${fieldname}").val();
		$("#articleDlg_${fieldname} [name='relatedid']").each(function(i){
			if(this.checked){
			 if(value!="")value= value+",";
			 value =value+this.value;
			}
		});
		$("#relatedArea_${fieldname}").val(value);
		alert("成功加入关联，您可以继续选择!");
	}
};

$(function(){
	Related_${fieldname}.init();
});
</script>